package com.dykj.fireFighting.web.controller.government;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.dykj.fireFighting.api.base.government.entity.GovListView;
import com.dykj.fireFighting.api.base.government.entity.GovernmentList;
import com.dykj.fireFighting.api.base.government.entity.GovernmentProject;
import com.dykj.fireFighting.api.base.government.entity.GovernmentProjectView;
import com.dykj.fireFighting.api.base.government.service.*;
import com.dykj.fireFighting.common.core.annotation.AutoLog;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.common.core.vo.LoginUserVo;
import com.dykj.fireFighting.web.base.shiro.ShiroUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

@Slf4j
@Api(value = "精准治理-专项治理-接口", tags = {"精准治理-专项治理接口"})
@RestController
@RequestMapping("/GovernmentList")
public class GovernmentListController {
    /**
     * 精准治理-专项治理列表
     *
     * @return
     */
    @DubboReference
    private IGovListViewService govListViewService;
    @DubboReference
    private IGovernmentListService governmentListService;
    @AutoLog(value = "精准治理-治理清单-分页列表查询")
    @ApiOperation(value = "精准治理-治理清单分页列表", notes = "精准治理-治理清单分页列表")
    @GetMapping("/list")
    public CommonResult treeGrid(@RequestParam(value = "page",required = false)Integer page,
                                                @RequestParam(value = "limit",required = false)Integer limit,
                                String sName,String beginTime, String endTime) {

        return CommonResult.success(govListViewService.getPageList(sName,beginTime,endTime,page,limit));
    }
    @PostMapping("/delbyid")
    public CommonResult delbyid(@RequestBody String[] ids) {
        try {
            governmentListService.removeByIds(Arrays.asList(ids));
            return CommonResult.success("删除成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }
    @PostMapping("/save")
    public CommonResult saveorup(@Valid @RequestBody GovernmentList governmentList) {
        String id=governmentList.getId();
        LoginUserVo u = ShiroUtil.getUser();
        if(StringUtils.equals("0",id)){
            governmentList.setId(IdUtil.simpleUUID());
            governmentList.setCreateBy(u.getId()+"");
            governmentList.setCreateTime(DateUtil.date());
        }
        governmentList.setUpBy(u.getId()+"");
        governmentListService.saveOrUpdate(governmentList);
        return CommonResult.success("操作成功！");
    }
    @AutoLog(value = "消防车-获取消防车信息")
    @ApiOperation(value = "获取消防车信息", notes = "获取消防车信息")
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", dataType = "String", required = true)
    @GetMapping("/getbyid/{id}")
    public CommonResult<Map<String,Object>> info(@PathVariable("id") String id) {
        Map<String,Object> reMap = new HashMap<>();
        reMap.put("govlist",governmentListService.getById(id));
        reMap.put("govview",govListViewService.getById(id));
        return CommonResult.success(reMap);
    }

}
